# -*- coding: utf-8 -*-
# @File     : serializers.py
# @Author   : bingjia
# @Time     : 2020/8/11 10:32
# @Desc     :

from operation.base.api import serializers

from . import models


class NetworkSerializer(serializers.ModelSerializer):
    """
    网络序列化
    """
    class Meta:
        model = models.NetworkModel
        fields = ['id', 'name', 'description']


class ModelSerializer(serializers.ModelSerializer):
    """
    模型序列化
    """
    image_type = serializers.SerializerMethodField()
    network_model = serializers.SerializerMethodField()
    train_user = serializers.SerializerMethodField()

    class Meta:
        model = models.ModelInfo
        fields = ['id', 'name', 'iterations_number', 'image_type',
                  'category_number', 'category_info', 'network_model',
                  'created_date', 'train_user', 'description']

    def get_image_type(self, obj):
        return obj.get_image_type_display

    def get_network_model(self, obj):
        return obj.network_model.name

    def get_train_user(self, obj):
        return obj.train_user.full_name





